/**
 * @ngdoc overview
 * @name yuanlinApp
 * @description
 * # yuanlinApp
 *
 * Main module of the application.
 */
define(function (require, exports, module) {
  'use strict';
  var app = angular.module('yuanlinApp', [
    'ngCookies',
    'ngResource',
    'ngRoute',
    'ngTouch',
    'LocalStorageModule',
    'ngFileUpload',
    'angular-lazyload'
  ]);
  require('./services/mh-services')(app);
  require('./services/mh-directives')(app);
  app.config(['$routeProvider', 'localStorageServiceProvider', '$httpProvider',
    function ($routeProvider, localStorageServiceProvider, $httpProvider) {
      localStorageServiceProvider.setPrefix('yuanlinApp');
      //改变默认设置，使其可以正常提交post数据
      $httpProvider.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded;charset=utf-8';

      /**
       * The workhorse; converts an object to x-www-form-urlencoded serialization.
       * @param {Object} obj
       * @return {String}
       */
      var param = function (obj) {
        var query = '', name, value, fullSubName, subName, subValue, innerObj, i;

        for (name in obj) {
          value = obj[name];

          if (value instanceof Array) {
            for (i = 0; i < value.length; ++i) {
              subValue = value[i];
              fullSubName = name + '[' + i + ']';
              innerObj = {};
              innerObj[fullSubName] = subValue;
              query += param(innerObj) + '&';
            }
          }
          else if (value instanceof Object) {
            for (subName in value) {
              subValue = value[subName];
              fullSubName = name + '[' + subName + ']';
              innerObj = {};
              innerObj[fullSubName] = subValue;
              query += param(innerObj) + '&';
            }
          }
          else if (value !== undefined && value !== null)
            query += encodeURIComponent(name) + '=' + encodeURIComponent(value) + '&';
        }

        return query.length ? query.substr(0, query.length - 1) : query;
      };

      // Override $http service's default transformRequest
      $httpProvider.defaults.transformRequest = [function (data) {
        return angular.isObject(data) && String(data) !== '[object File]' ? param(data) : data;
      }];
      $routeProvider
        .when('/login', {
          //登录
          templateUrl: 'views/login.html',
          controller: 'LoginCtrl',
          controllerUrl: 'scripts/controllers/login.js'
        }).when('/register', {
          //注册
          templateUrl: 'views/register.html',
          controller: 'RegisterCtrl',
          controllerUrl: 'scripts/controllers/register.js'
        }).when('/personal', {
          //个人中心
          templateUrl: 'views/personal.html',
          controller: 'PersonalCtrl',
          controllerUrl: 'scripts/controllers/personal.js'
        }).when('/quote', {
          //报价
          templateUrl: 'views/quote.html',
          controller: 'QuoteCtrl',
          controllerUrl: 'scripts/controllers/quote.js'
        }).when('/material/:flag', {
          //添加材料、查看材料
          templateUrl: 'views/material.html',
          controller: 'MaterialCtrl',
          controllerUrl: 'scripts/controllers/material.js'
          }).when('/supplierList', {
              //查看材料供应商
              templateUrl: 'views/supplier-list.html',
              controller: 'supplier-list',
              controllerUrl: 'scripts/controllers/supplier-list.js'
          }).when('/materialDetails', {
              //查看材料供应商
              templateUrl: 'views/material-detail.html',
              controller: 'material-detail',
              controllerUrl: 'scripts/controllers/material-detail.js'
        }).when('/programmedCosts', {
          //实施计划成本
          templateUrl: 'views/programmed-costs.html',
          controller: 'ProgrammedCostsCtrl',
          controllerUrl: 'scripts/controllers/programmed-costs.js'
        }).when('/quoteSettle', {
          //报价表格
          templateUrl: 'views/quote-settle.html',
          controller: 'QuoteSettleCtrl',
          controllerUrl: 'scripts/controllers/quote-settle.js'
        }).when('/quoteSubmit', {
          //报价提交
          templateUrl: 'views/quote-submit.html',
          controller: 'quoteSubmitCtrl',
          controllerUrl: 'scripts/controllers/quote-submit.js'
        }).when('/projectList', {
          //工程提报
          templateUrl: 'views/project-list.html',
          controller: 'ProjectListCtrl',
          controllerUrl: 'scripts/controllers/project-list.js'
        }).when('/processList/:projectId', {
          //工序列表
          templateUrl: 'views/process-list.html',
          controller: 'ProcessListCtrl',
          controllerUrl: 'scripts/controllers/process-list.js'
        }).when('/projectAdd/:flag', {
          //新增工程提报
          templateUrl: 'views/project-add.html',
          controller: 'ProjectAddCtrl',
          controllerUrl: 'scripts/controllers/project-add.js'
        }).when('/projectSettle', {
          //提报详情
          templateUrl: 'views/project-settle.html',
          controller: 'ProjectSettleCtrl',
          controllerUrl: 'scripts/controllers/project-settle.js'
        }).when('/steel/:flag', {
          //流程列表
          templateUrl: 'views/steel.html',
          controller: 'SteelCtrl',
          controllerUrl: 'scripts/controllers/steel.js'
        }).when('/moduleList/:flag', {
          //模块列表
          templateUrl: 'views/module-list.html',
          controller: 'ModuleListCtrl',
          controllerUrl: 'scripts/controllers/module-list.js'
        }).when('/costreport', {
          //完结申请
          templateUrl: 'views/cost-report.html',
          controller: 'CostReportCtrl',
          controllerUrl: 'scripts/controllers/cost-report.js',
          controllerAs: 'costReport'
        }).when('/costcheck', {
          //审批申请
          templateUrl: 'views/cost-check.html',
          controller: 'CostCheckCtrl',
          controllerUrl: 'scripts/controllers/cost-check.js',
          controllerAs: 'costCheck'
        }).when('/building', {
          //楼盘地图
          templateUrl: 'views/building.html',
          controller: 'BuildingCtrl',
          controllerUrl: 'scripts/controllers/building.js'
        }).when('/selectCity', {
          //选择城市--wujianjin
          templateUrl: 'views/selectCity.html',
          controller: 'selectCityCtrl',
          controllerUrl: 'scripts/controllers/selectCity.js'
        }).when('/saleData/:Id', {
          //销售数据
          templateUrl: 'views/sale-data.html',
          controller: 'SaleDataCtrl',
          controllerUrl: 'scripts/controllers/sale-data.js'
        }).when('/sale/add', {
          //新建销售数据
          templateUrl: 'views/sale-add.html',
          controller: 'SaleAddCtrl',
          controllerUrl: 'scripts/controllers/sale.add.js'
        }).when('/interviewData/:Id', {
          //走访数据
          templateUrl: 'views/interview-data.html',
          controller: 'InterviewDataCtrl',
          controllerUrl: 'scripts/controllers/interview-data.js'
        }).when('/interview/add', {
          //新建走访数据
          templateUrl: 'views/interview-add.html',
          controller: 'InterviewAddCtrl',
          controllerUrl: 'scripts/controllers/interview.add.js'
        }).when('/renovation', {
          //走访——装修户数据
          templateUrl: 'views/renovation.html',
          controller: 'RenovationCtrl',
          controllerUrl: 'scripts/controllers/renovation.js'
        }).when('/occupancy', {
          //走访入住户数据
          templateUrl: 'views/occupancy.html',
          controller: 'OccupancyCtrl',
          controllerUrl: 'scripts/controllers/occupancy.js'
        }).when('/verifyList', {
          //签单列表
          templateUrl: 'views/verify-list.html',
          controller: 'VerifyListCtrl',
          controllerUrl: 'scripts/controllers/verify-list.js'
        }).when('/myVerifyList', {
          //我的签单列表
          templateUrl: 'views/my-verify-list.html',
          controller: 'MyVerifyListCtrl',
          controllerAs: 'myVerifyList',
          controllerUrl: 'scripts/controllers/my-verify-list.js'
        }).when('/myVerifyDetail/:Id', {
          //我的签单详情
          templateUrl: 'views/my-verify-detail.html',
          controller: 'MyVerifyDetailCtrl',
          controllerAs: 'myVerifyDetail',
          controllerUrl: 'scripts/controllers/my-verify-detail.js'
        }).when('/verifyAdd', {
          //新建签单
          templateUrl: 'views/verify-add.html',
          controller: 'VerifyAddCtrl',
          controllerUrl: 'scripts/controllers/verify-add.js'
        }).when('/verifyQuoteDetail/:flag', {
          //报价审核详情
          templateUrl: 'views/verify-quote-detail.html',
          controller: 'VerifyQuoteDetailCtrl',
          controllerUrl: 'scripts/controllers/verify-quote-detail.js'
        }).when('/verifyQuote/:flag', {
          //报价审核
          templateUrl: 'views/verify-quote.html',
          controller: 'VerifyQuoteCtrl',
          controllerUrl: 'scripts/controllers/verify-quote.js'
        }).when('/feedList', {
          //提料列表
          templateUrl: 'views/feed-list.html',
          controller: 'FeedListCtrl',
          controllerUrl: 'scripts/controllers/feed-list.js'
        }).when('/feedAdd/:flag', {
          //添加提料
          templateUrl: 'views/feed-add.html',
          controller: 'FeedAddCtrl',
          controllerUrl: 'scripts/controllers/feed-add.js'
        }).when('/feedApply', {
          //添加提料
          templateUrl: 'views/feed-apply.html',
          controller: 'FeedApplyCtrl',
          controllerUrl: 'scripts/controllers/feed-apply.js'
        }).when('/message', {
          //消息列表
          templateUrl: 'views/message-list.html',
          controller: 'MessageListCtrl',
          controllerUrl: 'scripts/controllers/message-list.js'
        }).when('/feedManage', {
          //提料管理 Wayne
          templateUrl: 'views/feed-Manage.html',
          controller: 'FeedManageCtrl',
          controllerUrl: 'scripts/controllers/feed-Manage.js'
        }).when('/showFeedDetail/:Id', {
          //提料详情 Wayne
          templateUrl: 'views/feed-detail.html',
          controller: 'FeedDetailCtrl',
          controllerUrl: 'scripts/controllers/feed-detail.js'
        }).when('/warehouse', {
          //填写入库验收 Wayne
          templateUrl: 'views/warehouse.html',
          controller: 'warehouseCtrl',
          controllerUrl: 'scripts/controllers/warehouse.js'
        }).when('/record/:resolveid&:rName', {
          //苗木档案列表 Wayne
          templateUrl: 'views/record.html',
          controller: 'recordCtrl',
          controllerUrl: 'scripts/controllers/record.js'
        }).when('/filloutRecord', {
          //填写苗木档案 Wayne
          templateUrl: 'views/filloutRecord.html',
          controller: 'filloutRecordCtrl',
          controllerUrl: 'scripts/controllers/filloutRecord.js'
        }).when('/tempmodeAdd', {
          //消息列表
          templateUrl: 'views/tempmode-add.html',
          controller: 'TempModeAddCtrl',
          controllerUrl: 'scripts/controllers/tempmode-add.js'
        }).when('/tempplanAdd', {
          //消息列表
          templateUrl: 'views/tempplan-add.html',
          controller: 'TempPlanAddCtrl',
          controllerUrl: 'scripts/controllers/tempplan-add.js'
        }).when('/tempmodeAdd', {
          //消息列表
          templateUrl: 'views/tempmode-add.html',
          controller: 'TempModeAddCtrl',
          controllerUrl: 'scripts/controllers/tempmode-add.js'
        }).when('/tempplanAdd', {
          //消息列表
          templateUrl: 'views/tempplan-add.html',
          controller: 'TempPlanAddCtrl',
          controllerUrl: 'scripts/controllers/tempplan-add.js'
        })
        .otherwise({
          redirectTo: '/login'
        });
    }]);
  app.run(['$lazyload', function ($lazyload) {
    $lazyload.init(app);
    app.register = $lazyload.register;
  }]);

  app.factory('tempData', function() {
    var data = {};
    return data;
  });

  module.exports = app;
});
